resource "local_file" "inventory" {
  content = <<-DOC
    # Ansible inventory containing variable values from Terraform.
    # Generated by Terraform.

    [nodes:children]
    webservers
    databases 
    storage 

    [webservers]
    %{~ for i in webservers ~}
    ${i["name"]}   ansible_host=${i["network_interface"][0]["nat_ip_address"]}  ansible_port=22
    %{~ endfor ~}


    [databases]
    %{~ for i in databases ~}
    ${i["name"]}   ansible_host=${i["network_interface"][0]["nat_ip_address"]} ansible_port=22
    %{~ endfor ~}
    
    
    [storage]
    %{~ for i in storage ~}
    ${i["name"]}   ansible_host=${i["network_interface"][0]["nat_ip_address"]} ansible_port=22
    %{~ endfor ~}
    
    DOC
  
 filename = "../ansible/inventory"
  
  
}